<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="author" content="featon inc.">
    <link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/vendor/bootstrap/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="/static/vendor/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/vendor/jqPagination/css/jqpagination.css">

    <link href="/static/vendor/jquery-easyui/themes/default/tree.css" rel="stylesheet">
    <link href="/static/vendor/jquery-easyui/themes/icon.css" rel="stylesheet">
    <link href="/static/vendor/jquery-ui/themes/base/jquery.ui.all.css" rel="stylesheet">

    <link rel="stylesheet" href="/static/vendor/skin/ftskin.css">

    <title>信息列表</title>
</head>

<body>
<div class="ft-subpage-wrapper container-fluid">

    <!-- 左导航开始	-->
    <div id="ftsidebar-subpage" style="overflow:auto;" class="ft-sidebar-box-subpage">
        <div class="leftTree-box">
            <ul id="leftTree" class="easyui-tree" animate="true">

            </ul>
        </div>
    </div>
    <!-- 左导航结束	-->

    <!-- 主窗口开始	-->
    <div id="ftmainBox" class="ft-mainBox">
        <div class="row">
            <div class="container-fluid">
                <div class="col-lg-12">
                    <div class="tools-box">
                        <button type="button" class="btn btn-info" onclick="openAddPage()"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span> 添加</button>
                        <button type="button" class="btn btn-warning" onclick="updateRecord(table,'id','openUpdatePage()');"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> 修改</button>
                        <button type="button" class="btn btn-danger" onclick="deleteRecord(table,'id','deleteObject()');"><span class="glyphicon glyphicon-remove" aria-hidden="true"></span> 删除</button>
                        <button type="button" class="btn btn-success" onclick="sortRecord(table,'id','sortObject()');"><span class="glyphicon glyphicon-floppy-saved" aria-hidden="true"></span> 保存排序</button>
                    </div>
                </div>
            </div>
        </div>


        <div class="row">
            <div class="container-fluid">
                <div class="col-lg-12" id="table">

                </div>
            </div>
        </div>

        <div class="row">
            <div class="container-fluid">
                <div id="turn">

                </div>
            </div>
        </div>

    </div>
    <!-- 主窗口结束	-->

</div>
<script src="/static/vendor/jquery/jquery-2.1.3.min.js"></script>
<script src="/static/vendor/bootstrap/js/bootstrap.min.js"></script>

<script src="/static/vendor/jquery-ui/minified/jquery-ui.min.js"></script>
<script src="/static/vendor/jquery-easyui/jquery.easyui.min.js"></script>

<link rel="stylesheet" href="/static/vendor/custom-scrollbar/jquery.mCustomScrollbar.min.css">
<script src="/static/vendor/custom-scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>

<script src="/static/vendor/jqPagination/js/jquery.jqpagination.min.js"></script>
<script src="/static/vendor/skin/js/ft-ui.js"></script>
<script src="/static/vendor/skin/js/tree-util.js"></script>
<script src="/static/vendor/skin/js/table-common.js"></script>
<script src="/static/vendor/skin/js/java.js"></script>
<script src="/static/vendor/skin/js/jquery.c.js"></script>
<script>
    var dict_cat_id = '';
    var tp = new TurnPage();
    var table = new Table();
    table.table_name = "table_list";
    var beanList = null;
    var jsonData;
    var con_map = new Map();
    $(document).ready(function(){
        init_page();   //初始化页面内各BOX高度

        //table_input_init("dataTables-example-01"); //初始化input全选
        $("#ftsidebar-subpage").mCustomScrollbar({
            theme:"minimal-dark"
        });

        initTable();
        showCateTree();
        loadListble();
    });

    $(window).resize(function(){
        init_page();
    });

    //初始化页面内各BOX高度
    function init_page()
    {
        var window_height = $(window).height();

        $("#ftmainBox").css("height",window_height-38);
        $("#ftsidebar-subpage").css("height",window_height-58);

    }

    function showCateTree()
    {
        var cat_list = top.ajax.synclBody("/dictCategory/getDictCategoryList",'');
        if(cat_list != null && cat_list.length > 0)
        {
            var json = '';
            dict_cat_id = cat_list[0].dict_cat_id
            for(var i=0;i<cat_list.length;i++)
            {
                json += ',{"id":"'+cat_list[i].dict_cat_id+'","text":"'+cat_list[i].dict_cat_name+'"}';
            }
            showCateTreeHandl(eval("["+json.substring(1)+"]"));
        }
    }

    function showCateTreeHandl(obj)
    {
        json_data = obj;
        setLeftMenuTreeJsonData(json_data);
        initMenuTree();
        treeNodeSelected(dict_cat_id);
    }

    function initMenuTree()
    {
        $('#leftTree').tree({
            onClick:function(node){
                changeDeptListTable(node.id);
            }
        });

    }

    //点击树节点,修改用户列表数据
    function changeDeptListTable(m_id){
        dict_cat_id = m_id;
        loadListble();
    }

    function initTable(){

        var colsMap = new Map();
        var colsList = new List();

        colsList.add(setTitleClos("dict_name","名称","270px","","",""));
        colsList.add(setTitleClos("action_col","操作","100px","","",""));
        colsList.add(setTitleClos("sort_col","排序","100px","","",""));
        colsList.add(setTitleClos("dict_code","代码","100px","","",""));
        colsList.add(setTitleClos("is_use","是否可选","100px","","",""));
        colsList.add(setTitleClos("is_default","是否默认","80px","","",""));
        colsList.add(setTitleClos("space_cell","","","","",""));

        table.setColsList(colsList);
        table.setAllColsList(colsList);
        table.enableSort=false;//禁用表头排序
        table.onSortChange = showList;
        table.show("table");//里面参数为外层div的id
    }

    function loadListble()
    {
        tp.curr_page = 1;
        showList();
        showTurnPage();
    }

    function showList(){
        beanList = top.ajax.synclBody("/dictCategory/getDictList/"+dict_cat_id,con_map.toJSON())
        tp.total = beanList.length;
        curr_bean = null;
        table.setBeanList(beanList,"td_list");//设置列表内容的样式
        table.show("table");


        table.getCol("action_col").each(function(i){
            if(i>0)
            {
                $(this).html('<a href="javascript:openUpdatePage(\''+beanList[i-1].id+'\')">编辑</a>&nbsp;&nbsp;<a href="javascript:deleteSingleObject(\''+beanList[i-1].id+'\')">删除</a>');
            }
        });

        table.getCol("sort_col").each(function(i){
            if(i>0)
            {
                $(this).html(getSortColStr());
            }
        });


        table.getCol("is_use").each(function(i){
            if(i>0)
            {
                switch(beanList[i-1].is_use){
                    case 0:$(this).text("不可选");break;
                    case 1:$(this).text("");break;
                }
            }
        });

        table.getCol("is_default").each(function(i){
            if(i>0)
            {
                switch(beanList[i-1].is_default){
                    case 0:$(this).text("");break;
                    case 1:$(this).text("默认");break;
                }
            }
        });
        table_input_init(table.table_name);
    }

    function showTurnPage(){

        tp.show("turn","");
        tp.onPageChange = showList;
    }

    function openAddPage()
    {
        modelWindow.openFrameWindow("维护字典","/dictCategory/go_dict_add?dict_cat_id="+dict_cat_id,600,410);
    }

    function openUpdatePage(id)
    {
        var sel_id = '';
        if(id != '' && id != null)
        {
            sel_id = id;
        }else
            sel_id = table.getSelecteCheckboxValue("id");
        modelWindow.openFrameWindow("维护字典","/dictCategory/go_dict_add?id="+sel_id,600,410);
    }

    function deleteObject(id)
    {
        var sel_id = '';
        if(id != '' && id != null)
        {
            sel_id = id;
        }else
            sel_id = table.getSelecteCheckboxValue("id");
        var dm = new Map();
        dm.put('id',"'"+sel_id.replace(/,/ig,"','")+"'");
        if(top.ajax.synclBody("/dictCategory/delDict",dm.toJSON()))
        {
            modelWindow.alert("字典信息"+top.CMSLang.Delete_success);
            loadListble();
        }else
        {
            modelWindow.error("字典信息"+top.CMSLang.Delete_fail);
        }
    }

    function deleteSingleObject(id)
    {
        modelWindow.confirm("是否删除该条记录","deleteObject('"+id+"')")
    }

    function sortObject()
    {
        var ids = table.getAllCheckboxValue("id");
        if(ids != "" && ids != null)
        {
            let sm = new Map();
            sm.put("id", ids)
            if(top.ajax.syncl("/dictCategory/sortDict", JSON.stringify(sm)))
            {
                modelWindow.alert(top.CMSLang.Sort_success);
            }
            else
            {
                modelWindow.error(top.CMSLang.Sort_fail);
                return;
            }
        }
    }
</script>
</body>
</html>
